from django.db import models
from datetime import datetime,timedelta
from shops.models import Shops,Dishes



# 用户表
class UserModel(models.Model):
    account = models.CharField(max_length=20,verbose_name='账户')
    nickname = models.CharField(max_length=20,null=True,verbose_name='昵称')
    password = models.CharField(max_length=256,verbose_name='密码')
    mobile = models.CharField(max_length=11,verbose_name='手机号')
    profile_photo = models.CharField(max_length=800,null=True,verbose_name='头像')
    login_time = models.DateTimeField(default=datetime.now(),null=True,verbose_name='登陆时间')
    class Meta:
        db_table ='user_tb'
        verbose_name = '用户表'
        verbose_name_plural = verbose_name
    def __str__(self):
        return '用户名称:%s'%self.nickname


# 收货地址表
class Address(models.Model):
    recipients = models.CharField(max_length=50,verbose_name='收件人')
    recipients_mobile = models.CharField(max_length=11,verbose_name='手机号')
    recipients_addr = models.CharField(max_length=100,verbose_name='收件人地址')
    is_default = models.BooleanField("是否默认",default=False)
    user = models.ForeignKey(UserModel,on_delete=models.CASCADE,verbose_name="所属用户")
    class Meta:
        db_table="address_tb"
        verbose_name_plural="收货地址"
    def __str__(self):
        return '用户的收货地址%s'%self.recipients + " " + self.recipients_addr


# 优惠券
class User_Coupon(models.Model):
    coupon_id = models.IntegerField(verbose_name='优惠券id')
    user = models.ForeignKey(UserModel,on_delete=models.CASCADE,verbose_name="用户id")
    class Meta:
        db_table="user_coupon_tb"
        verbose_name_plural="用户的优惠券"
    def __str__(self):
        return '用户的优惠券%s'%self.coupon_id





# 聊天 沟通
class Chat(models.Model):
    room_id = models.CharField('房间号(商家ID_顾客ID)', max_length=10, null=True)
    user = models.ForeignKey(verbose_name="用户", to=UserModel, on_delete=models.CASCADE, null=True)
    shops = models.ForeignKey(verbose_name="商家", to=Shops, on_delete=models.CASCADE, null=True)
    content = models.CharField('聊天内容', max_length=100,null=True)
    state = models.IntegerField(verbose_name="0用户1商家", default=0)

    class Meta:
        db_table = 'chat_content'

    def __str__(self):
        return self.content
